<script>
$(document).ready(function(){ 
    $("#dialog").dialog({ title: '<?=ucfirst($this->actionName) .' '.ucfirst($this->controllerName)?> ' });
})


$("#dialog").dialog( "option", "width", $(window).width()*0.95 ).dialog( "option", "height", $(window).height()*0.9).dialog( "option", "position", [10,0]);
$(window).resize(function() {
    $("#dialog").dialog( "option", "width", $(window).width()*0.95 ).dialog( "option", "height", $(window).height()*0.9).dialog( "option", "position", [10,0]);
});


$('input[name*=storage]').css('width',40);
$('input[name*=ram]').css('width',40);
$('input[name*=internet]').css('width',40);
$('input[name*=backup]').css('width',60);
$('input[name*=firewall]').css('width',60);





$("#ajax_form select[name=id_proyecto]").change(function () {
    var id_proyecto=$(this).val();
    if(id_proyecto)
    {
        $.post('/proyecto/getjson', {col:'orden',id: id_proyecto,idZona:'<?= $this->idZona ?>'},function(data){
    			$("#ajax_form input[name=pep]").val(data.orden);	    
        }); 
    }else{
        $("#ajax_form input[name=pep]").val('');
    } 
})




$('#n_maquinas').keyup(function() {  
    for (i=1;i<=16;i++){
        $('#server'+i).empty();
    }
    var n_maquinas= $('#n_maquinas').val();
    for (i=1;i<=n_maquinas;i++){
        $('#fila_servidor').clone().appendTo('#server'+i);
    }
});  


function Isx50(objeto){
	var value=$(objeto).val();
	
    if (value%50!=0) {
		$(objeto).css('border','2px solid #FF2A2A')
		$(objeto).focus()
		alert('El campo storage solo puede ser multiplo de 50.')
		return false;
	}
    
	$(objeto).css('border','1px solid #C0C0C0')
	return true;
}

function Is124(objeto){
	var value=$(objeto).val();

    if(value=='')return true;
    if (value!=1 && value!=2 && value!=4) {
		$(objeto).css('border','2px solid #FF2A2A')
		$(objeto).focus()
		alert('El campo RAM solo puede ser 1, 2 o 4.')
		return false;
	}
    
	$(objeto).css('border','1px solid #C0C0C0')
	return true;
}


function validate(formData, jqForm, options) { 

    if(!$("#ajax_form input[name=pep]").val() && !$("#ajax_form select[name=id_proyecto]").val()){
        alert('Se necesita Cliente o PEP');
        return false; 
    }

    if(!IsRequired('#ajax_form select[name=id_proyecto]','Proyecto'))return false; 
     
    if(!IsRequired('#ajax_form input[name=fecha_alta]','Fecha Alta'))return false; 
    
    
    var error = false;
    $('#ajax_form input[name*="storage"]').map(function() {
         if(!Isx50(this)) error=true; 
    })
    $('#ajax_form input[name*="ram"]').map(function() {
         if(!Is124(this)) error=true; 
    })
    $('#ajax_form select[name*="id_tipo_servidor"]').map(function() {
        if(!IsRequired(this,'Tipo Servidor')) error=true; 
    })
    $('#ajax_form input[name*="internet"]').map(function() {
        if(!IsInteger(this,'internet')) error=true; 
    })
        
    if(error)    return false; 
    else  return true; 
}


</script>



<?php


$this->form->setAction($this->url())->setAttrib('id', 'ajax_form');

?>



<form action="<?php echo $this->form->getAction()?>" method="<?php echo $this->form->getMethod()?>" id="ajax_form">


<table class="tableform">
<tr>
    <td><?echo $this->form->getElement('id_proyecto');?></td>
    <td><?echo $this->form->getElement('pep');?></td>
</tr>
<tr>
    <td><?echo $this->form->getElement('ticket_nec');?></td>
    <td><?echo $this->form->getElement('ticket_cliente');?></td>
</tr>
<tr>
    <td><?echo $this->form->getElement('fecha_alta');?></td>
    <td><?echo $this->form->getElement('fecha_baja');?></td>
</tr>

</table>


<table class="tableform" id="fila_servidor" width="80%">
<tr>
    <th>Tipo Servidor</th>
    <th>Nombre Servidor</th>
    <th>LUN</th>
    <th>Exceso Storage (GB)</th>
    <th>Extra RAM (GB)</th>
    <th>Internet (Mbps)</th>
    <th>Monitorización</th>
    <th>Backup (GB)</th>
    <th>Firewall (Reglas)</th>
</tr>
<?for ($i=1;$i<=5;$i++):?>
<tr>
    <td><?echo $this->form->getElement('id_tipo_servidor'.$i);?></td>
    <td><?echo $this->form->getElement('nombre_servidor'.$i);?></td>
    <td><?echo $this->form->getElement('lun'.$i);?></td>
    <td><?echo $this->form->getElement('storage'.$i);?></td>
    <td><?echo $this->form->getElement('ram'.$i);?></td>
    <td><?echo $this->form->getElement('internet'.$i);?></td>
    <td><?echo $this->form->getElement('monitor'.$i);?></td>
    <td><?echo $this->form->getElement('backup'.$i);?></td>
    <td><?echo $this->form->getElement('firewall'.$i);?></td>
    
</tr>
<?endfor?>
</table>



</form>


<?php

echo $this->partial('form_js.phtml', 
    array(	
        'actionName'=>$this->actionName,
        'id'=>$this->id,
        'id_tablesorter'=>$this->id_tablesorter,
        )
);


